$.widget("ui.FileUploader", {
    _create: ->
        div = $(@element).closest("div")
        div.addClass("file-upload")
        value = $(@element).val()
        if (value && value.length)
            div.append('<a class="no-link" href="' + value + '">Download</a>')
        path = Settings.UploadPath
        div.append('<span><input type="file" value=""/><span>Upload</span></span>')
        div.find("span input").fileupload({
            dataType: "text"
            url: SiteMap.Shared.FileUpload
            sequentialUploads: true
            start: (e)->
                Loading.Start() 
            done: (e, data) ->
                $(this).closest(".image-upload").find("input[type = hidden]").val(data.result)
                Messages.WriteMessage("File uploaded successfully")
                $(this).closest(".file-upload").find("a").remove()
                $(this).closest(".file-upload").append('<a class="no-link" href="' + path + data.result + '">Download</a>')
                $(this).closest(".file-upload").find("input[type=hidden]").val(data.result).closest("fieldset>div").trigger("validate")

                Loading.Stop()
            fail: (e, data) ->
                Messages.WriteMessage("Unexpected error");
                Loading.Stop()
        })
})